using System.Collections;
using System.Reflection;
using BussinesLayerLogicTier;
using DataLayer;

namespace BussinesLayerDataTier
{
	/// <summary>
	/// Coleccion de DataObject
	/// </summary>
	public class DataObjectCollection : CollectionBase 
	{
		private Hashtable loadKeys = new Hashtable();
		private ReloadType reloadType;
		
		public void UpdateLoadKeys()
		{
			//Generate LoadKeys each time the object is created
			
			LoadKeys.Clear();
			
			foreach (PropertyInfo pi in GetType().GetProperties())
			{
				foreach (FieldAttribute fa in pi.GetCustomAttributes(typeof(FieldAttribute),false))
				{
					if (fa.PrimaryKey)
					{
						LoadKeys.Add(fa.Name,pi.GetValue(this,null));		
					}
				}
			}
		}

		public Hashtable LoadKeys
		{
			get { return loadKeys ; }
			set { loadKeys = value; }
		}

		public ReloadType ReloadType
		{
			get { return reloadType; }
			set { reloadType = value; }
		}
		
		public int Add(DataObject obj)
		{
			return List.Add(obj);
		}
		
		public void Insert(int index, DataObject obj)
		{
			List.Insert(index,obj);
		}
		
		public void Remove(DataObject obj)
		{
			List.Remove(obj);
		} 
		
		public bool Contains(DataObject obj)
		{
			return List.Contains(obj);
		}
		
		public int IndexOf(DataObject obj)
		{
			return List.IndexOf(obj);
		}
		
		public void CopyTo(DataObject[] array, int index)
		{
			List.CopyTo(array, index);
		}
		
		public DataObject this[int index]
		{
			get { return (DataObject)List[index]; }
			set { List[index] = value; }
		}

	}
}
